package project;

import java.util.Random;

/**
 * animal class,which is defined by all of the following attributes,
 * each of the individual animals will get their own attributes from here
 * @author dalyj1
 *
 */
public class Animal {
   public String name;
   public String owner;
   public String classID;
   public int size;
   public int speed;
   public int str;
   public int dex;
   public int intel;
   public int age;
   public int hp;
   public int humour;
   public int xpos;
   public int ypos;
   public int wins;
   public int losses;

   public String toString(){
       return this.name;
   }
   
   /**
    * iniitialises all of the attributes giving certain values to some attributes
    * suck as health points which is the same for all animals
    */
  
   /**iniitialises all of the attributes giving certain values to some attributes
    * suck as health points which is the same for all animals
    * @param sp value to give speed
    * @param st value to give strength
    * @param d value to give dexterity
    * @param inte value to give intelligence
    * @param nme Name to be given to animal
    * @param pwn Name to be give to owner
    */
public Animal(int sp,int st,int d,int inte,String nme,String pwn){
       size = 1;
       speed = sp;
       dex = d;
       str = st;
       intel = inte;
       age = 0;
       hp = 40;
       humour = 0;
       xpos = 0;
       ypos = 0;
       wins = 0;
       losses = 0;
       name = nme;
       owner = pwn;
   }
/**
 * This is used to create Animals with random attributes for debug purposes.
 * @param n Name to give Animal
 */
public Animal(final String n){
       final Random random = new Random( );
       this.name = n;
       this.classID = "Ape";
       this.size = Math.abs(random.nextInt()%11);
       this.speed = Math.abs(random.nextInt()%11);
       this.dex = Math.abs(random.nextInt()%11);
       this.str = Math.abs(random.nextInt()%11);
       this.intel = Math.abs(random.nextInt()%11);
       this.age = Math.abs(random.nextInt()%11);
       this.humour = 0;
       this.xpos = 0;
       this.ypos = 0;
       this.wins = 0;
       this.losses = 0;
       this.owner = "Me!";
   }

/** 
 * Used to set the value of a field easily by XML.java in the Platform subpackage.
 * @param field Name of field to set
 * @param value Value to set field to
 */
public void setValue(final String field, final String value){
       if (field.equals("name"))
           this.name = value;
       else if (field.equals("owner"))
           this.owner = value;
       else if (field.equals("classID"))
           this.classID = value;
       else if (field.equals("size"))
           this.size = Integer.parseInt(value);
       else if (field.equals("speed"))
           this.speed = Integer.parseInt(value);
       else if (field.equals("strength"))
           this.str = Integer.parseInt(value);
       else if (field.equals("dexterity"))
           this.dex = Integer.parseInt(value);
       else if (field.equals("intelligence"))
           this.intel = Integer.parseInt(value);
       else if (field.equals("age"))
           this.age = Integer.parseInt(value);
       else if (field.equals("humour"))
           this.humour = Integer.parseInt(value);
       else if (field.equals("xPosition"))
           this.xpos = Integer.parseInt(value);
       else if (field.equals("yPosition"))
           this.ypos = Integer.parseInt(value);
       else if (field.equals("wins"))
           this.wins = Integer.parseInt(value);
       else if (field.equals("losses"))
           this.losses = Integer.parseInt(value);
   }

   /**
    * returns animal size
 * @return size
 */
public int getSize(){
		return size;
	}
   /** increases animal size */

	public void incSize(){
		size++;
	}
	
	/**
	 * returns animal speed
	 * @return speed
	 */
	public int getSpeed(){
		return speed;
	}
	/** increases animal speed */
	public void incSpeed(){
		speed++;
	}	
	/**
	 * returns animal dexterity
	 * @return dexterity
	 */
	public int getDex(){
		return dex;
	}
	/** increase animal dexterity */
	public void incDex(){
		dex++;
	}
	/**
	 * returns
	 * @return strength
	 */
	public int getStrength(){
		return str;
	}
	/** increases animal strength */
	public void incStrength(){
		str++;
	}

	
	/**
	 * returns animal intelligence
	 * @return intelligence
	 */
	public int getIntelligence(){
		return intel;
	}
	/** increases animal intelligence */
	public void incIntelligence(){
		intel++;
	}
	
	/**
	 * returns animal age
	 * @return animal age
	 */
	public int getAge(){
		return age;
	}
	/** increases animals age */
	public void incAge(){
		age++;
	}
	/**
	 * returns animal humour
	 * @return Animal humour
	 */
	public int getHumour(){
		return humour;
	}
	/** changes value of humour to make animal happy */
	public void makeHappy(){
		humour = 0;
	}
	/** changes value of humour to make animal sad */
	public void makeSad(){
		humour = 1;
	}
	/** changes value of humour to make animal angry */
	public void makeAngry(){
		humour = 2;
	}
	
	/**
	 * returns animal health points
	 * @return Aniamls health points
	 */
	public int getHP(){
		return hp;
	}
	/** increase animal health points */
	public void increaseHP(){
		hp++;
	}
	/** decreases animal health points */
	public void decreaseHP(int i){
		hp = hp -i;
	}	
	/**
	 * returns animal X pos on grid
	 * @return Xpos
	 */
	public int getXpos(){
		return xpos;
	}
	/**
	 * returns animal X pos on grid
	 * @return Ypos
	 */
	public int getYpos(){
		return ypos;
	}
	/** increases animal wins */
	public void incWins(){
		wins++;
	}
	/** increases animal loses */
	public void incLosses(){
		losses++;
	}
	/* returns animal name */
	/**
	 * returns animal name
	 * @return Animals name
	 */
	public String getName(){
		return name;
	}
	/**
	 * returns Animals owner
	 * @return Animal owner
	 */
	public String getOwner(){
		return owner;
	}
	
	/**
	 * returns value for the stat
	 * @param i Stat that is reference by integer i
	 * @return value of attack
	 */
	public int getRandomStat(int i){
		if(i==0){
			return dex;
		}else if(i==1){
			return speed;
		}
		else if(i==2){
			return str;
		}
		else if(i==3){
			return intel;
		}else{
			return str;
		}
	}
	/** moves animal to the right */
	public void moveRight(){
		ypos++;
	}
	/** moves animal to the left */
	public void moveLeft(){
		ypos--;
	}
	/** moves animal up */
	public void moveUp(){
		xpos--;
	}
	/** moves animal down */
	public void moveDown(){
		xpos++;
	}
	/** moves animal up and to the right */
	public void moveUpRight(){
		ypos++;
		xpos--;
	}
	/** moves the animal up and to the left */
	public void moveUpLeft(){
		ypos--;
		xpos--;
	}
	/** moves the animal down and to the right */
	public void moveDownRight(){
		ypos++;
		xpos++;
	}
	/** moves the animal down and to the left */
	public void moveDownLeft(){
		ypos--;
		xpos++;
	}
   
}